package com.woniuxy.weixindemo.service.impl;

import com.woniuxy.weixindemo.service.AsyncService;
import com.woniuxy.weixindemo.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO:
 * <P> Date: 2022/5/31:18:18
 * <P> Description:
 */
@Service
@Slf4j
public class AsyncServiceImpl implements AsyncService {

    @Override
    @Async("asyncServiceExecutor")
    public void executeAsync(CyclicBarrier cyclicBarrier) {
        try {
            log.warn("执行任务开始 executeAsync");
            //异步线程要做的事情

            cyclicBarrier.await();

        } catch (BrokenBarrierException | InterruptedException e) {
            e.printStackTrace();
        } finally {
            log.warn("执行任务结束 executeAsync");
        }
    }


}
